﻿Imports MindFusion.Diagramming
Imports MindFusion.Drawing

Public Class ClsMMActorNode
Inherits ShapeNode
    'represents actor node in use case diagram

#Region "Attributes"
#Region "Private attributes"
    Private MiID As Integer = -1 'MY OWN ID for this node. ID identifies this node - useful during synchroselection in compare version mode
    Private MbHasRTFnote As Boolean = False 'table RTF note indicator
#End Region
#End Region
#Region "Constructors"
Public Sub New()
    MyBase.New()
    AddID()
    MMSetDefaultProperties()
End Sub

Public Sub New(ByVal parent As MindFusion.Diagramming.Diagram)
    MyBase.New(parent)
    AddID()
    MMSetDefaultProperties()
End Sub

Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramItem)
    MyBase.New(prototype)
    AddID()
End Sub

Public Sub New(ByVal prototype As MindFusion.Diagramming.DiagramNode)
    MyBase.New(prototype)
    AddID()
End Sub

Public Sub New(ByVal prototype As MindFusion.Diagramming.ShapeNode)
    MyBase.New(prototype)
    AddID()
End Sub
#End Region
#Region "Properties"
#Region "Public properties"
    'Public ReadOnly Property MMRectangleForNewLink() As RectangleF
    '    Get
    '        Return SDRectangleFVirginCreator(Me.Bounds.Left + (Me.Bounds.Width / 2) - 2, Me.Bounds.Top + (Me.Bounds.Height / 2) - 2, 4, 4)
    '    End Get
    'End Property
    Public ReadOnly Property ID() As Integer
        Get
            Return MiID
        End Get

    End Property
    Public Property HasRTFnote() As Boolean
        Get
            Return MbHasRTFnote
        End Get
        Set(ByVal IbValue As Boolean)
            MbHasRTFnote = IbValue
        End Set
    End Property
#End Region
#End Region
#Region "Subs"
#Region "Overrides & Overloads Subs"
'overrided sub for saving to XML
Protected Overrides Sub SaveToXml(ByVal xmlElement As System.Xml.XmlElement, ByVal context As MindFusion.Diagramming.XmlPersistContext)
    MyBase.SaveToXml(xmlElement, context)
        context.WriteString(CStr(MiID), "ID", xmlElement)
        context.WriteString(IIf(MbHasRTFnote, "TRUE", "FALSE"), "HasRTFnote", xmlElement)
End Sub
'overrided sub for loading from XML
Protected Overrides Sub LoadFromXml(ByVal xmlElement As System.Xml.XmlElement, ByVal context As MindFusion.Diagramming.XmlPersistContext)
    MyBase.LoadFromXml(xmlElement, context)
        MiID = CInt(context.ReadString("ID", xmlElement))
        MbHasRTFnote = IIf((context.ReadString("HasRTFnote", xmlElement)).ToUpper = "TRUE", True, False)
End Sub
    'overrided sub for drawing a shape
    Public Overrides Sub Draw(ByVal graphics As MindFusion.Drawing.IGraphics, ByVal options As MindFusion.Diagramming.RenderOptions)
        MyBase.Draw(graphics, options)

        ''drawing triangle for shape note indication
        'If MbHasRTFnote Then DrawNoteTriangle(Me.Bounds, graphics)
    End Sub
    ''overrided sub for drawing handles
    'Public Overrides Sub DrawHandles(ByVal graphics As MindFusion.Drawing.IGraphics, ByVal color As System.Drawing.Color)
    '    MyBase.DrawHandles(graphics, color)

    '    'Debug.Print("DrawHandles")
    '    Const LdbWidthOfLine As Double = 0.7
    '    Const LdbWidthOfLineForRectangle As Double = 0.5

    '    'drawing filled rectangle for creating new link
    '    Dim LoBrush As System.Drawing.Drawing2D.HatchBrush = New System.Drawing.Drawing2D.HatchBrush(Drawing2D.HatchStyle.LightUpwardDiagonal, Drawing.Color.Black, Drawing.Color.LightCoral)
    '    Dim LoRectangleF As RectangleF = New RectangleF(MMRectangleForNewLink.X, MMRectangleForNewLink.Y, MMRectangleForNewLink.Width, MMRectangleForNewLink.Height - IIf(Me.Pen.Width = 0, MindFusion.Diagramming.Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width) / 2)
    '    graphics.FillRectangle(LoBrush, LoRectangleF)
    '    'drawing rectangle around filled rectangle
    '    Dim LoPen As System.Drawing.Pen = New System.Drawing.Pen(color.Gray, LdbWidthOfLineForRectangle)
    '    LoPen.DashStyle = Drawing2D.DashStyle.Solid
    '    'Dim LoRectangle As Rectangle = New Rectangle(LoRectangleF.X, LoRectangleF.Y, LoRectangleF.Width, LoRectangleF.Height )
    '    LoRectangleF.Height -= IIf(Me.Pen.Width = 0, MindFusion.Diagramming.Constants.GetPixel(Me.Parent.MeasureUnit), Me.Pen.Width) / 2
    '    graphics.DrawRectangles(LoPen, New RectangleF() {LoRectangleF})

    '    'drawing selection rectangle
    '    graphics.DrawRectangle(SDPenVirginCreator(color, LdbWidthOfLine), CType(Me.Bounds.X - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Y - LdbWidthOfLine / 2, Single), CType(Me.Bounds.Width + LdbWidthOfLine, Single), CType(Me.Bounds.Height + LdbWidthOfLine, Single))
    'End Sub
'overrided sub called after deserialization of node. I can set some properties forcible here!
Protected Overrides Sub OnLoad()
    MyBase.OnLoad()
    End Sub
#End Region
#Region "MM Subs"
'adds ID for this node. ID identifies this node - useful during synchroselection in compare version mode
Private Sub AddID()
    Dim LoRandomGenerator As Random = New Random(Now.Millisecond)
        MiID = LoRandomGenerator.Next
End Sub
'default settings of shape
Public Sub MMSetDefaultProperties()
        Me.Shape = Shapes.Actor
        Me.Constraints.MinHeight = 10
        Me.Constraints.MinWidth = 10
        Me.Obstacle = True ' whether this node is considered an obstacle by the link-routing algorithm
        Me.Bounds = SDRectangleVirginCreator(0, 0, 20, 30)
        Me.EnableStyledText = True 'whether styled text rendering is enabled
        Me.AnchorPattern = CreateAnchorPatternSurrounding(9) 'Represents a set of anchor points, which specify the exact locations where links are allowed to connect to nodes
        Me.CustomDraw = CustomDraw.Additional 'The custom painting code executes after item's interior and frame are painted by FlowChart.NET, but before text is rendered. In this mode, the Graphics instance passed to the custom drawing event handler has a clipping region applied to it
        Me.Font = New Font("Arial", 8, FontStyle.Regular) 'font used to render the node's text
        Me.TextColor = Color.White
        Me.AllowIncomingLinks = True 'true - because of creation of notes
        Me.AllowOutgoingLinks = True 'true - because of creation of notes
        Me.Brush = New LinearGradientBrush(Color.FromArgb(55, 154, 183), Color.FromArgb(45, 125, 148), 90) 'brush is used to fill the interiors of geometric shapes
        Me.Pen = New Pen("0/#FF696969/0/0/0//0/0/10/") 'pen is used to draw the outline of geometric shapes
        Me.HandlesStyle = HandlesStyle.SquareHandles2  'visual styles for frames that are drawn around selected nodes
        Me.ShadowOffsetX = 0.5 'horizontal offset of the shadow
        Me.ShadowOffsetY = 0.5 'vertical offset of the shadow
        'Me.ImageAlign = ImageAlign.MiddleRight 'the position and alignment of a picture relative to its destination rectangle
        Me.Text = GsStringDefaultValue 'the text displayed inside the shape node
    End Sub
    'routes links (depends on parameters - all incoming or all outgoing)
Public Sub MMRouteLinks(Optional ByVal IbRouteIncomingLinks As Boolean = True, Optional ByVal IbRouteOutgoingLinks As Boolean = True)
    If IbRouteIncomingLinks Then
        For Each LoLink As DiagramLink In IncomingLinks
            LoLink.Route()
        Next
    End If

    If IbRouteOutgoingLinks Then
        For Each LoLink As DiagramLink In OutgoingLinks
            LoLink.Route()
        Next
    End If
    End Sub
    'resizes text area of shape in subordinate group
    Public Sub MMResizeTextArea()
        If Me.SubordinateGroup IsNot Nothing Then
            CType(Me.SubordinateGroup.AttachedNodes(1), ClsMMTextNode).MMResizeAll()
        End If
    End Sub
    'sets visibility of node for creating new lik
    Public Sub MMSetVisibilityOfNodeForNewLink(ByVal IbValue As Boolean)
        If Me.SubordinateGroup IsNot Nothing Then
            CType(Me.SubordinateGroup.AttachedNodes(0), ClsMMNodeForNewLink).Visible = IbValue
        End If
    End Sub
#End Region
#End Region

End Class


